import { ICustomer , ISaleInfoCustomer, ISaleInfoMoney, ISaleInfoContract} from '@/types/pages/customer/interface';
import { PageDateSelect } from '@/types/pages/enum';
import {excuteScriptService} from './scriptUtil';
import axios from 'axios';
import Mock from 'mockjs'
import { IDateLineChart, IDatePieChart } from '@/types/echart';

/**
 * 客户数量
 * @param type
 * @param date
 * @returns
 */
export const getSaleInfoCustomerData:(type:PageDateSelect,date?:Date)=>Promise<ISaleInfoCustomer>=function(type:PageDateSelect,date?:Date){
//  return axios.post('/getSaleInfoCustomerData',{type,date})
let serviceConfig = {
  objName: 'system.shyk_bi_hr_ryjg',
  serviceName: 'getJNDJPieData',
  version: 'v2',
  params: {
      linkageParam: JSON.stringify({})
  }
};

  return new Promise((res,rej)=>{
    // 调用supos天基服务获取动态数据
    excuteScriptService(serviceConfig, (data:any) => {
      res(data);
    })

      let data=Mock.mock({unit:'', num:'283', saleRate:'24%',comparisonText:'比去年',upDownStatus:false,addNum:'19',freezeNum:'5'})
        if(type===PageDateSelect.mounth){
          data=Mock.mock({ unit:'', num:'30', saleRate:'14%',comparisonText:'比去年',upDownStatus:false,addNum:'15',freezeNum:'1'})
        }
        if(type===PageDateSelect.day){
          data=Mock.mock({unit:'', num:'3', saleRate:'30%',comparisonText:'比去年',upDownStatus:false,addNum:'5',freezeNum:'1'})
        }

        res(data);
    })
}
/**
 * 销售额
 * @param type
 * @param date
 * @returns
 */
export const getSaleInfoMoneyData:(ype:PageDateSelect,date?:Date)=>Promise<ISaleInfoMoney>=function(type:PageDateSelect,date?:Date){
  return new Promise((res,rej)=>{
    // num="28714" unit="万元"
    let data=Mock.mock({unit:'千万', num:'143923', saleRate:'2%',comparisonText:'比去年',upDownStatus:false,averageNum:'123' , averageUnit:'万元'})
      if(type===PageDateSelect.mounth){
        data=Mock.mock({unit:'千万', num:'3923', saleRate:'14%',comparisonText:'比去年',upDownStatus:false,averageNum:'34' , averageUnit:'万元' })
      }
      if(type===PageDateSelect.day){
        data=Mock.mock({unit:'千万', num:'123', saleRate:'3%',comparisonText:'比去年',upDownStatus:false,averageNum:'55' , averageUnit:'万元'})
      }
      res(data);
  })

}
/**
 * 销售合同
 * @param type
 * @param date
 * @returns
 */
export const getSaleInfoContractData:(type:PageDateSelect,date?:Date)=>Promise<ISaleInfoContract>=function(type:PageDateSelect,date?:Date){
  return new Promise((res,rej)=>{
    // totalNum="85000" saleNum="81260"
    let data=Mock.mock({ unit:'千万', num:'143923', saleRate:'5%',comparisonText:'比去年',upDownStatus:false,totalNum:'85000',saleNum:'81260'})
      if(type===PageDateSelect.mounth){
        data=Mock.mock({unit:'千万', num:'3923', saleRate:'6%',comparisonText:'比去年',upDownStatus:false,totalNum:'5000',saleNum:'1260'})
      }
      if(type===PageDateSelect.day){
        data=Mock.mock({unit:'千万', num:'123', saleRate:'7%',comparisonText:'比去年',upDownStatus:false ,totalNum:'1000',saleNum:'60'})
      }

      res(data);
  })

}


export const getPieLeftChart:(ype:PageDateSelect,date?:Date)=>Promise<IDatePieChart>=function(type:PageDateSelect,date){
    return new Promise((res,rej)=>{
      const dataset:IDatePieChart={title:'产品类别销售占比1',dataset:{dimensions:['成分','价格'],'source':[{'成分':'聚酯级'+Mock.Random.cname(),'价格|1-100':100,},{'成分':'聚酯级'+Mock.Random.cname(),'价格|1-100':100,},{'成分':'聚酯级'+Mock.Random.cname(),'价格|1-100':100,}]}}
      res(Mock.mock(dataset));
    })
}
export const getPieRightChart:(ype:PageDateSelect,date?:Date)=>Promise<IDatePieChart>=function(type:PageDateSelect,date){
    return new Promise((res,rej)=>{
      const dataset:IDatePieChart={title:'产品类别销售占比1',dataset:{dimensions:['成分','价格'],'source':[{'成分':'聚酯级'+Mock.Random.cname(),'价格|1-100':100,},{'成分':'聚酯级'+Mock.Random.cname(),'价格|1-100':100,},{'成分':'聚酯级'+Mock.Random.cname(),'价格|1-100':100,}]}}
        res(Mock.mock(dataset));
    })
}

export const getLineChart:(ype:PageDateSelect,date?:Date)=>Promise<IDateLineChart>=function(type:PageDateSelect,date){
    return new Promise((res,rej)=>{
      const a=()=>(Math.random()*100).toFixed(2)
      const dataset:IDateLineChart={title:'产品类别销售占比',dataset:{dimensions:['date','实际','预测'],source:[{'date':'2021-01-7','实际':a(),'预测':a()},{'date':'2021-01-8','实际':a(),'预测':a()}]}}
      res(Mock.mock(dataset));
    })
}


export const getColumnChart:(ype:PageDateSelect,date?:Date)=>Promise<IDateLineChart>=function(type:PageDateSelect,date){
  return new Promise((res,rej)=>{
    const a=()=>(Math.random()*100).toFixed(2)
    const dataset:IDateLineChart={title:'客户销售排名top10',dataset:{dimensions:['客户','数值'],source:[{'客户':Mock.Random.cname(),'数值':a()},{'客户':Mock.Random.cname(),'数值':a()},{'客户':Mock.Random.cname(),'数值':a()},{'客户':Mock.Random.cname(),'数值':a()}]}}
    res(Mock.mock(dataset));

  })
}
